#include "StdAfx.h"
#include "MaterialWindow.h"
#include "LitStream.h"

namespace Lit
{
	namespace Editor
	{	
		namespace Material
		{			
			Window::Window( const std::string &name, const std::string &project_name, QMdiArea * area ) : QMdiSubWindow( area ), mArea(area), mName(name), mProjectName(project_name)
			{
				setMinimumSize( 250, 150 );
				setStyle( new QWindowsVistaStyle() );
				setWindowTitle( TO_QT(name) );
				setWindowIcon( QIcon(":/Icons/script.png") );
				
				mEditor = new EditorWidget( this );
				setWidget( mEditor );

				connect( mEditor, SIGNAL(modifiedStateChanged(bool)), this, SLOT(modifiedStateChanged(bool)) );
			}
			Window::~Window()
			{}

			TextEdit * Window::getCodeEditor(){
				assert( mEditor ); 
				return mEditor->getUi()->textEdit;
			}
			const TextEdit * Window::getCodeEditor() const{
				assert( mEditor ); 
				return mEditor->getUi()->textEdit;
			}
			EditorWidget * Window::getEditor(){
				assert( mEditor ); 
				return mEditor;
			}
			const EditorWidget * Window::getEditor() const{
				assert( mEditor ); 
				return mEditor;
			}
			void Window::closeEvent( QCloseEvent * evt )
			{
				evt->ignore();
				hide();
			}
			
			void Window::modifiedStateChanged( bool state )
			{
				setWindowTitle( state ?  TO_QT(mName+" *") : TO_QT(mName) );
			}
		};
	};
};